/**
 * 
 */
package com.runningfox.Process;

import java.util.ArrayList;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.runningfox.humor.AbstractProcess;
import com.runningfox.humor.Action;
import com.runningfox.humor.ProcessCallback;
import com.runningfox.logic.Logic;
import com.runningfox.model.Comment;
import com.runningfox.model.Joke;
import com.runningfox.model.ResultSet;

/**
 * @author lhy
 * 加载评论内容
 * 首先从本地缓存读取
 * 如果缓存没有，从网络读取
 */
public class LoadCommentProcess extends AbstractProcess implements ProcessCallback {
	Joke node;
	String page;
	
	public LoadCommentProcess(Handler handler, Joke node,String page) {
		super(handler);
		// TODO Auto-generated constructor stub
		this.node = node;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.runningfox.Humor.AbstractProcess#runImpl()
	 */
	@Override
	protected void runImpl() {
		// TODO Auto-generated method stub
		Logic.loadComments(node, page, this);
	}

	@Override
	public void onFailed(ResultSet res) {
		// TODO Auto-generated method stub
		this.handler.sendEmptyMessage(Action.LOADCOMMENTFAIL);
	}

	@Override
	public void onHttp200() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onHttp404() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onHttp500() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onHttpFaild() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onParseFail() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onParsing() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onSucess(ResultSet res) {
		// TODO Auto-generated method stub
		Message msg = new Message();
		Bundle data = new Bundle();
		msg.what = Action.LOADCOMMENT;
		ArrayList<Comment> commentList= res.commentList;
		data.putParcelableArrayList("comments", commentList);
//		data.putString("page", res.page);
		msg.setData(data);
		handler.sendMessage(msg);
	}

}
